<!--该画面是：报价单维护画面 -->
<template>
  <el-dialog
    id="backCombineAccount"
    v-loading="dataLoading"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(255, 255, 255, 0.7)"
    :title="title"
    :visible.sync="openSheet"
    width="1200px"
    :destroy-on-close="true"
    :close-on-click-modal="false"
    :before-close="cancel"
  >
    <!-- 项目计划信息 -->
    <projectplanbase-info :project-plan-base-information="projectPlanBaseInformation" />
    <!-- 项目计划信息 -->

    <div class="DescriptionTitle">{{ $t('projectCombineAccountTitle') }}</div>

    <el-table ref="table1" v-loading="loading" :data="accountList" border :style="{ height: tableHeightStyle }" :default-sort="{ prop: 'quote_date', order: 'ascending' }">
      <el-table-column :label="$t('projectMaintainName')" prop="project_name" align="center" width="220" />
      <el-table-column :label="$t('projectMaintainSalesDate')" prop="sales_date" align="center" width="120" />
      <el-table-column :label="$t('maintainAccountSalesAmount')" prop="sales_amount" align="right" width="120" />
      <el-table-column :label="$t('maintainAccountAmount')" prop="amount" align="right" width="120" />
      <el-table-column :label="$t('maintainAccountProfitLoss')" prop="profit_loss" align="right" width="120" />
      <el-table-column :label="$t('projectMaintainNote')" prop="note" min-width="220" show-tooltip-when-overflow />
      <el-table-column :label="$t('operate')" align="center" width="180" class-name="fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="updateAccount(scope.row)">{{ $t('modifyBtn') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <pagination
      v-show="detailtotal > 0"
      :pager-count="5"
      :total="detailtotal"
      :page.sync="detailParams.page"
      :limit.sync="detailParams.page_size"
      @pagination="getaccountList"
    /> -->

    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">{{ $t('cancel') }}</el-button>
    </div>

    <el-backtop target="#backCombineAccount" />
    <projectcombineaccount-maintain-sheet ref="projectcombineaccountMaintainSheet" @refreshList="getaccountList" />
  </el-dialog>
</template>

<script>
import { getCombineAccountApi } from '@/views/project/projectaccount/api/projectcombineaccount.api';
import projectplanbaseInfo from '@/views/projectbase/projectplanbase/components/projectplanbase-info.vue';
import projectcombineaccountMaintainSheet from './projectcombineaccount-maintain-sheet.vue';

export default {
  components: { projectplanbaseInfo, projectcombineaccountMaintainSheet },
  data() {
    return {
      title: this.$t('projectCombineAccountTitle'),
      dataLoading: false,
      loading: false,
      openSheet: false,
      accountList: [],
      detailtotal: 0,
      detailParams: {
        projectPlanFK: undefined,
        page: 1,
        page_size: 10
      },
      options: [],
      projectPlanId: undefined,
      projectPlanBaseInformation: {},
      tableHeightStyle: '',
      originalTableHeight: ''
    }
  },
  methods: {
    async openSheetDialog(data) {
      this.dataLoading = true;
      this.reset();
      this.projectPlanBaseInformation = data
      this.projectPlanId = data.id;
      this.getaccountList();
      this.openSheet = !this.openSheet;
      this.dataLoading = false;
    },
    // 获取合并后的核算（开发、维护）履历数据
    async getaccountList() {
      this.loading = true
      var resp = await getCombineAccountApi(this.projectPlanId)
      console.log(resp)
      if (resp.success) {
        this.accountList = resp.data
        this.detailtotal = resp.data.length
      } else {
        this.accountList = []
      }
      this.updateTableHeight();
      this.loading = false
    },
    updateTableHeight() {
      this.tableHeightStyle = ''
      // 确保表格数据渲染完成
      this.$nextTick(() => {
        setTimeout(() => {
          // 再次确保 DOM 已经更新
          this.tableHeightStyle = this.$refs.table1.$el.scrollHeight + 'px';
        }, 100); // 增加 100ms 的延迟
      });
    },
    cancel() {
      this.openSheet = !this.openSheet;
      this.$emit('refreshList');
      this.reset()
    },
    reset() {
      this.detailtotal = 0
      this.detailParams = {
        projectPlanFK: undefined,
        page: 1,
        page_size: 10
      };
      this.accountList = []
    },
    // 修改按钮
    updateAccount(row) {
      this.$refs.projectcombineaccountMaintainSheet.openSheetDialog(row)
    }
  }
};
</script>

  <style scoped>
  @import "~@/views/projectbase/projectcss/project.css";
  </style>
